package com.caption.core.exception;
import com.caption.core.model.enums.BaseResultEnum;
import com.caption.core.model.enums.ResultEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
 * @description: 自定义封装异常类
 * @author: 码农
 * @date: 2022-01-01 00:27:57
 */
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class ServiceException extends RuntimeException {
    private Integer code;
    private String desc;

    public ServiceException() {
        super(BaseResultEnum.SERVICE_ERROR.getDesc());
        this.code = BaseResultEnum.SERVICE_ERROR.getCode();
        this.desc = BaseResultEnum.SERVICE_ERROR.getDesc();
    }


    public ServiceException(String message) {
        super(message);
        this.desc = message;
        this.code = BaseResultEnum.SERVICE_ERROR.getCode();
    }

    public ServiceException(Integer code, String message) {
        super(message);
        this.code = code;
        this.desc = message;
    }

    public ServiceException(ResultEnum<Integer> resultEum) {
        super(resultEum.getDesc());
        this.code = resultEum.getCode();
        this.desc = resultEum.getDesc();
    }


    public ServiceException(Throwable cause) {
        super(cause);
        this.code = BaseResultEnum.SERVICE_ERROR.getCode();
        this.desc = BaseResultEnum.SERVICE_ERROR.getDesc();
    }

    public ServiceException(String message,Throwable cause) {
        super(message,cause);
        this.code = BaseResultEnum.SERVICE_ERROR.getCode();
        this.desc = message;
    }

    public ServiceException(ResultEnum<Integer> resultEum, Throwable cause) {
        super(resultEum.getDesc(), cause);
        this.code = resultEum.getCode();
        this.desc = resultEum.getDesc();
    }

    public ServiceException(Integer code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.desc = message;
    }



}
